/*
 * Created on May 4, 2004
 *
 * Vectrics Inc.  GNU Public License.
 */

package org.vectrics.company;

import java.util.Comparator;

import org.vectrics.company.Company;


/**
 * @author mmoore
 */

public class CompanyNameThenDivisionComparator implements Comparator {

	public int compare(Object obj1, Object obj2) {
		Company company1 = (Company)obj1;
		Company company2 = (Company)obj2;
		
		String key1 = findCompanyKey(company1);
		String key2 = findCompanyKey(company2);
		
		return(key1.compareTo(key2));
	}
	
	public String findCompanyKey(Company company) {
		String key = company.getName();
		if (company.getParent() != null) {
			key = findCompanyKey(company.getParent()) + "." + key;
		}
		return(key);
	}
	
}
